#include "StdAfx.h"
#include "cTexture.h"

cTexture::cTexture(void)
{
	colorBuffer = NULL;
}

cTexture::~cTexture(void)
{
	if(colorBuffer)
		delete colorBuffer;
	colorBuffer = NULL;
}
int cTexture::Init(char* fileName)
{
	colorBuffer = LoadTGA(fileName, &width, &height,&bpp); 
	if(colorBuffer)
	{
		glGenTextures( 1, &textureId);
		glBindTexture(GL_TEXTURE_2D, textureId);
		glTexImage2D(GL_TEXTURE_2D,0,bpp==24?GL_RGB:GL_RGBA,width,height,0,bpp==24?GL_RGB:GL_RGBA,GL_UNSIGNED_BYTE,colorBuffer);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,m_State);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,m_State);
		glGenerateMipmap(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, 0);
		return 1;
	}
	return 0;
}
